package com.github.tj123.common;

import com.github.tj123.common.convert.BeanConvertException;
import com.github.tj123.common.convert.BeanUtil;

import java.lang.reflect.ParameterizedType;

/**
 * Po 接口
 */
public interface Po<DTO extends Dto<?>> extends Mapable {

    /**
     * 转 DTO
     *
     * @return
     */
    default DTO toDto() throws BeanConvertException {
        return (DTO) BeanUtil.convert(this, (Class<?>) ((ParameterizedType) getClass()
                .getGenericSuperclass()).getActualTypeArguments()[0]);
    }
}
